package team.yidong.fenda.utils;

import org.springframework.stereotype.Component;

import javax.activation.MimetypesFileTypeMap;
import java.io.File;

/**
 * Created by xuanlong on 2017/10/11.
 */

/**
 * 通过判断文件头信息来判断上传的文件是否为图片
 */
@Component
public class ImageCheck {

    public static Boolean isImage(byte[] b) {
        if (b[0] == (byte) 'G' && b[1] == (byte) 'I' && b[2] == (byte) 'F') {
            return true;
        } else if (b[1] == (byte) 'P' && b[2] == (byte) 'N' && b[3] == (byte) 'G') {
            return true;
        } else if (b[6] == (byte) 'J' && b[7] == (byte) 'F' && b[8] == (byte) 'I' && b[9]    == (byte) 'F') {
            return true;
        } else {
            return false;
        }

    }
}
